<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <script type="text/javascript" src="${ctx}/appjs/market/marketActivity.js"></script>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>运营管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>编辑营销活动</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });

</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">增加营销活动</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="frmMarketActivity">
                        <input type="hidden" name="marketActivityId" id="marketActivityId"
                               value="${marketActivity.marketActivityId}">
                        <input type="hidden" name="status" id="status" value="${marketActivity.status}">
                        <input type="hidden" name="tenantCode" id="tenantCode" value="${marketActivity.tenantCode}">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">活动类型：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="activityType" id="activityType">
                                    <option value="0">新用户注册送优惠</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">活动名称：</label>
                            <div class="col-sm-3">
                                <input class="form-control" name="activityName" id="activityName"
                                       value="${marketActivity.activityName}">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">奖励类型：</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="rewardType" name="rewardType">
                                    <option value="0">赠送优惠券</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">赠送对象：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="sendType" id="sendType">
                                    <option value="0">新用户</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">关联优惠券：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="ticketTypeId" id="ticketTypeId">
                                    <option value="">拉取优惠券页面的数据</option>
                                    <c:forEach items="${tenantTicketTypes}" var="tenantTicketType">
                                        <option value="${tenantTicketType.ticketTypeId}"
                                                <c:if test="${marketActivity.ticketTypeId == tenantTicketType.ticketTypeId}">selected</c:if>    >${tenantTicketType.ticketName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <%--<div class="form-group row">--%>
                        <%--<label class="col-sm-3 col-form-label text-right">优惠券剩余数量：</label>--%>
                        <%--<div class="col-sm-3">--%>
                        <%--<span class="eva-p1"><span class="remainTicket"></span></span>--%>
                        <%--</div>--%>
                        <%--</div>--%>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">奖品内容：</label>
                            <div class="col-sm-3">
                                <span class="eva-p1"><span class="reducedAmount"></span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">单次赠送数量：</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="sendCount" name="sendCount"
                                       value="${marketActivity.sendCount}">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">活动规则描述：</label>
                            <div class="col-sm-3">
                                <textarea class="form-control" id="remark"
                                          name="remark">${marketActivity.remark}</textarea>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">注册成功提示：</label>
                            <div class="col-sm-3">
                                <textarea class="form-control" id="registerPrompt"
                                          name="registerPrompt">${marketActivity.registerPrompt}</textarea>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">送券成功提示：</label>
                            <div class="col-sm-3">
                                <textarea class="form-control" id="sendPrompt" name="sendPrompt">${marketActivity.sendPrompt}</textarea>
                            </div>
                        </div>
                        <%--<div class="form-group row">--%>
                        <%--<label class="col-sm-3 col-form-label text-right">APP下载链接：</label>--%>
                        <%--<div class="col-sm-3">--%>
                        <%--<input class="form-control" id="appDownloadUrl" name="appDownloadUrl">--%>
                        <%--</div>--%>
                        <%--</div>--%>

                        <div class="form-group">
                            <div class="col-sm-3 col-sm-offset-8 text-right">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                            <div class="col-sm-1 col-sm-offset-8 text-right">
                                <a href="javascript:window.history.back()" class="btn btn-primary">取消</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    $(function () {
        $('#ticketTypeId').searchableSelect();
        $(".ibox-content").css("height", $(window).height() - 80)
    })

    $("#ticketTypeId").change(function () {

        $.ajax({
            url: prefix + "/selectTicketDetail",
            type: "GET",
            data: {
                'ticketTypeId': $("#ticketTypeId").val(),
            },
            success: function (data) {
                if (data.status == 200) {
                    if (data.data != null) {
                        $(".remainTicket").html(data.data.remainTicket + '张')
                        if (data.data.discountType == 0) {
                            $(".reducedAmount").html('满' + data.data.useRequireAmount + '立减' + data.data.discountAmount)
                        } else if (data.data.discountType == 1) {
                            $(".reducedAmount").html('满' + data.data.useRequireAmount + '享' + (data.data.discount * 10) + '折')
                        }
                    } else {
                        $(".reducedAmount").html('')
                    }

                } else {
                    layer.msg(data.message);
                }
            },
            error: function (request) {
                layer.msg("查询失败");
                console.log(request)
            },
        });
    })


    addMarketActivity.init();
</script>
</body>
</html>
